import Vue from 'vue'

// 全局注册的组件(驼峰:变小写加-)
import Heads from '@/components/Heads.vue'
import VFoot from '@/components/VFoot.vue'
import Swiper from '@/components/Swiper.vue'
import Radios from '@/components/Radios.vue'
import Uploader from '@/components/Uploader.vue'
import Uploadavatar from '@/components/Uploadavatar.vue'
import SearchInput from '@/components/SearchInput.vue'
import FilmItem from '@/components/FilmItem.vue'
import FilmSwipe from '@/components/FilmSwipe.vue'
import MeiItem from '@/components/MeiItem.vue'

Vue.component('Heads', Heads)
Vue.component('VFoot', VFoot)
Vue.component('Swiper', Swiper)
Vue.component('Radios', Radios)
Vue.component('Uploader', Uploader)
Vue.component('Uploadavatar', Uploadavatar)
Vue.component('Search-input', SearchInput)
Vue.component('Film-item', FilmItem)
Vue.component('Film-swipe', FilmSwipe)
Vue.component('Mei-item', MeiItem)

/** */
/** */
/** */

// 全局的过滤器
Vue.filter('lower', function (value) {
  if (!value) {
    return
  }
  return value.toLowerCase()
})

Vue.filter('decimalPoint', function (value) {
  return (value / 100).toFixed(2)
})

Vue.filter('actorsFilter', function (value) {
  const list = value.map(item => item.name)
  return list.join('|')
})

Vue.filter('premiereAtFilter', function (value) {
  return value
})

// 自定义指令
Vue.directive('fdtitle', {
  inserted (el, bind) {
    // 插入到dom之后的钩子函数
    // console.log(bind.value)
    el.style.display = 'none'
    window.onscroll = () => {
      // console.log(document.documentElement.scrollTop)
      if ((document.documentElement.scrollTop || document.body.scrollTop) > bind.value) {
        // 显示
        el.style.display = 'block'
      } else {
        // 隐藏
        el.style.display = 'none'
      }
    }
  },
  unbind () {
    // 指令的解绑的生命周期 钩子函数
    window.onscroll = null
  }
})
